﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwObracunTemeljnicaZaKnjizenjeProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwObracunTemeljnicaZaKnjizenjeProviderBaseCore : EntityViewProviderBase<VwObracunTemeljnicaZaKnjizenje>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwObracunTemeljnicaZaKnjizenje&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwObracunTemeljnicaZaKnjizenje&gt;"/></returns>
		protected static VList&lt;VwObracunTemeljnicaZaKnjizenje&gt; Fill(DataSet dataSet, VList<VwObracunTemeljnicaZaKnjizenje> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwObracunTemeljnicaZaKnjizenje>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwObracunTemeljnicaZaKnjizenje&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwObracunTemeljnicaZaKnjizenje>"/></returns>
		protected static VList&lt;VwObracunTemeljnicaZaKnjizenje&gt; Fill(DataTable dataTable, VList<VwObracunTemeljnicaZaKnjizenje> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwObracunTemeljnicaZaKnjizenje c = new VwObracunTemeljnicaZaKnjizenje();
					c.Konto = (Convert.IsDBNull(row["Konto"]))?string.Empty:(System.String)row["Konto"];
					c.ObracunMjesec = (Convert.IsDBNull(row["ObracunMjesec"]))?(int)0:(System.Int32?)row["ObracunMjesec"];
					c.ObracunGodina = (Convert.IsDBNull(row["ObracunGodina"]))?(int)0:(System.Int32?)row["ObracunGodina"];
					c.IDObracun = (Convert.IsDBNull(row["IDObracun"]))?(int)0:(System.Int32)row["IDObracun"];
					c.DatumDo = (Convert.IsDBNull(row["DatumDo"]))?DateTime.MinValue:(System.DateTime)row["DatumDo"];
					c.Opis = (Convert.IsDBNull(row["Opis"]))?string.Empty:(System.String)row["Opis"];
					c.RedniBrojUGodini = (Convert.IsDBNull(row["RedniBrojUGodini"]))?(int)0:(System.Int32)row["RedniBrojUGodini"];
					c.Dug = (Convert.IsDBNull(row["Dug"]))?0:(System.Decimal?)row["Dug"];
					c.Pot = (Convert.IsDBNull(row["Pot"]))?0:(System.Decimal?)row["Pot"];
					c.VrDok = (Convert.IsDBNull(row["VrDok"]))?string.Empty:(System.String)row["VrDok"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwObracunTemeljnicaZaKnjizenje&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwObracunTemeljnicaZaKnjizenje&gt;"/></returns>
		protected VList<VwObracunTemeljnicaZaKnjizenje> Fill(IDataReader reader, VList<VwObracunTemeljnicaZaKnjizenje> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwObracunTemeljnicaZaKnjizenje entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwObracunTemeljnicaZaKnjizenje>("VwObracunTemeljnicaZaKnjizenje",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwObracunTemeljnicaZaKnjizenje();
					}
					entity.Konto = reader.IsDBNull(reader.GetOrdinal("Konto")) ? null : (System.String)reader["Konto"];
					//entity.Konto = (Convert.IsDBNull(reader["Konto"]))?string.Empty:(System.String)reader["Konto"];
					entity.ObracunMjesec = reader.IsDBNull(reader.GetOrdinal("ObracunMjesec")) ? null : (System.Int32?)reader["ObracunMjesec"];
					//entity.ObracunMjesec = (Convert.IsDBNull(reader["ObracunMjesec"]))?(int)0:(System.Int32?)reader["ObracunMjesec"];
					entity.ObracunGodina = reader.IsDBNull(reader.GetOrdinal("ObracunGodina")) ? null : (System.Int32?)reader["ObracunGodina"];
					//entity.ObracunGodina = (Convert.IsDBNull(reader["ObracunGodina"]))?(int)0:(System.Int32?)reader["ObracunGodina"];
					entity.IDObracun = (System.Int32)reader["IDObracun"];
					//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
					entity.DatumDo = (System.DateTime)reader["DatumDo"];
					//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime)reader["DatumDo"];
					entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
					//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
					entity.RedniBrojUGodini = (System.Int32)reader["RedniBrojUGodini"];
					//entity.RedniBrojUGodini = (Convert.IsDBNull(reader["RedniBrojUGodini"]))?(int)0:(System.Int32)reader["RedniBrojUGodini"];
					entity.Dug = reader.IsDBNull(reader.GetOrdinal("Dug")) ? null : (System.Decimal?)reader["Dug"];
					//entity.Dug = (Convert.IsDBNull(reader["Dug"]))?0:(System.Decimal?)reader["Dug"];
					entity.Pot = reader.IsDBNull(reader.GetOrdinal("Pot")) ? null : (System.Decimal?)reader["Pot"];
					//entity.Pot = (Convert.IsDBNull(reader["Pot"]))?0:(System.Decimal?)reader["Pot"];
					entity.VrDok = reader.IsDBNull(reader.GetOrdinal("VrDok")) ? null : (System.String)reader["VrDok"];
					//entity.VrDok = (Convert.IsDBNull(reader["VrDok"]))?string.Empty:(System.String)reader["VrDok"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwObracunTemeljnicaZaKnjizenje"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunTemeljnicaZaKnjizenje"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwObracunTemeljnicaZaKnjizenje entity)
		{
			reader.Read();
			entity.Konto = reader.IsDBNull(reader.GetOrdinal("Konto")) ? null : (System.String)reader["Konto"];
			//entity.Konto = (Convert.IsDBNull(reader["Konto"]))?string.Empty:(System.String)reader["Konto"];
			entity.ObracunMjesec = reader.IsDBNull(reader.GetOrdinal("ObracunMjesec")) ? null : (System.Int32?)reader["ObracunMjesec"];
			//entity.ObracunMjesec = (Convert.IsDBNull(reader["ObracunMjesec"]))?(int)0:(System.Int32?)reader["ObracunMjesec"];
			entity.ObracunGodina = reader.IsDBNull(reader.GetOrdinal("ObracunGodina")) ? null : (System.Int32?)reader["ObracunGodina"];
			//entity.ObracunGodina = (Convert.IsDBNull(reader["ObracunGodina"]))?(int)0:(System.Int32?)reader["ObracunGodina"];
			entity.IDObracun = (System.Int32)reader["IDObracun"];
			//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
			entity.DatumDo = (System.DateTime)reader["DatumDo"];
			//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime)reader["DatumDo"];
			entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
			//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
			entity.RedniBrojUGodini = (System.Int32)reader["RedniBrojUGodini"];
			//entity.RedniBrojUGodini = (Convert.IsDBNull(reader["RedniBrojUGodini"]))?(int)0:(System.Int32)reader["RedniBrojUGodini"];
			entity.Dug = reader.IsDBNull(reader.GetOrdinal("Dug")) ? null : (System.Decimal?)reader["Dug"];
			//entity.Dug = (Convert.IsDBNull(reader["Dug"]))?0:(System.Decimal?)reader["Dug"];
			entity.Pot = reader.IsDBNull(reader.GetOrdinal("Pot")) ? null : (System.Decimal?)reader["Pot"];
			//entity.Pot = (Convert.IsDBNull(reader["Pot"]))?0:(System.Decimal?)reader["Pot"];
			entity.VrDok = reader.IsDBNull(reader.GetOrdinal("VrDok")) ? null : (System.String)reader["VrDok"];
			//entity.VrDok = (Convert.IsDBNull(reader["VrDok"]))?string.Empty:(System.String)reader["VrDok"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwObracunTemeljnicaZaKnjizenje"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunTemeljnicaZaKnjizenje"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwObracunTemeljnicaZaKnjizenje entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Konto = (Convert.IsDBNull(dataRow["Konto"]))?string.Empty:(System.String)dataRow["Konto"];
			entity.ObracunMjesec = (Convert.IsDBNull(dataRow["ObracunMjesec"]))?(int)0:(System.Int32?)dataRow["ObracunMjesec"];
			entity.ObracunGodina = (Convert.IsDBNull(dataRow["ObracunGodina"]))?(int)0:(System.Int32?)dataRow["ObracunGodina"];
			entity.IDObracun = (Convert.IsDBNull(dataRow["IDObracun"]))?(int)0:(System.Int32)dataRow["IDObracun"];
			entity.DatumDo = (Convert.IsDBNull(dataRow["DatumDo"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumDo"];
			entity.Opis = (Convert.IsDBNull(dataRow["Opis"]))?string.Empty:(System.String)dataRow["Opis"];
			entity.RedniBrojUGodini = (Convert.IsDBNull(dataRow["RedniBrojUGodini"]))?(int)0:(System.Int32)dataRow["RedniBrojUGodini"];
			entity.Dug = (Convert.IsDBNull(dataRow["Dug"]))?0:(System.Decimal?)dataRow["Dug"];
			entity.Pot = (Convert.IsDBNull(dataRow["Pot"]))?0:(System.Decimal?)dataRow["Pot"];
			entity.VrDok = (Convert.IsDBNull(dataRow["VrDok"]))?string.Empty:(System.String)dataRow["VrDok"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwObracunTemeljnicaZaKnjizenjeFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunTemeljnicaZaKnjizenje"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunTemeljnicaZaKnjizenjeFilterBuilder : SqlFilterBuilder<VwObracunTemeljnicaZaKnjizenjeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunTemeljnicaZaKnjizenjeFilterBuilder class.
		/// </summary>
		public VwObracunTemeljnicaZaKnjizenjeFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTemeljnicaZaKnjizenjeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunTemeljnicaZaKnjizenjeFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTemeljnicaZaKnjizenjeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunTemeljnicaZaKnjizenjeFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunTemeljnicaZaKnjizenjeFilterBuilder

	#region VwObracunTemeljnicaZaKnjizenjeParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunTemeljnicaZaKnjizenje"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunTemeljnicaZaKnjizenjeParameterBuilder : ParameterizedSqlFilterBuilder<VwObracunTemeljnicaZaKnjizenjeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunTemeljnicaZaKnjizenjeParameterBuilder class.
		/// </summary>
		public VwObracunTemeljnicaZaKnjizenjeParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTemeljnicaZaKnjizenjeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunTemeljnicaZaKnjizenjeParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTemeljnicaZaKnjizenjeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunTemeljnicaZaKnjizenjeParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunTemeljnicaZaKnjizenjeParameterBuilder
} // end namespace
